<?php
/**
 * Created by PhpStorm.
 * User: 元曦
 * Date: 2023-02-22
 * Time: 9:45:22
 * Info: 内容模型模型
 */

namespace app\common\model;

use think\facade\Db;

class Models extends TimeInit
{

    /**
     * 获取模型列表
     */
    public static function getModelList($params = [])
    {
        $data = [];
        if ($params) {
            $limit = $params['limit'];
            $first = $params['first'];
            $field = $params['field'];
            $order = $params['order'];
        }
        $count = Models::count();
        $list  = Models::limit($first, $limit)->order($field, $order)->select();
        foreach ($list as $key => $v) {
            $v['index_tpl'] = $v['index_tpl'] ? $v['index_tpl'].'.html' : '';
            $v['list_tpl']  = $v['list_tpl'] ? $v['list_tpl'].'.html' : '';
            $v['show_tpl']  = $v['show_tpl'] ? $v['show_tpl'].'.html' : '';
            if ($v['type'] == 1) {
                $v['type'] = '单页';
            } else {
                $v['type'] = '列表';
            }
        }
        $data['list']  = $list ?? [];
        $data['count'] = $count ?? [];

        return $data;
    }

    /**
     * 获取模型
     *
     */
    public static function getModelsIdMenuList()
    {
        return Models::where('status', 1)->order('id asc')->select();
    }

    /**
     * 根据模型id获取模型别名
     * @return void
     */
    public function getModelAlias($model_id)
    {
        return $this->where('id', $model_id)->value('alias');
    }

}
